import axios from 'axios';
import { Pagination, PaginationData } from '@/types/global';

export interface CalculateWillApprovePathVo {
  processDefinitionKey: string;
  processInstanceId: string;
}
export interface FlowElementVO {
  id: string;
  name: string;
  type: string;
}
export function calculateWillApprovePath(params: CalculateWillApprovePathVo) {
  return axios.post<FlowElementVO[]>(
    `/flow/flow/calculateWillApprovePath`,
    params
  );
}

export interface DealerDTO {
  userId: string;
  userName: string;
  weight: string;
}

export interface FormStartDTO {
  data: object;
  id: string;
  path: string;
}

export interface ActivityDTO {
  dealerDTOs: DealerDTO[];
  description: string;
  id: string;
  multiTag: string;
  name: string;
  type: string;
}

export interface FlowStartDTO {
  title: string;
  processInstanceId: string;
  procDefinitionKey: string;
  remark: string;
  businessKey: string;
  activityDtos: ActivityDTO[];
  formStartDTO: FormStartDTO;
}

// 发起审批
export function startFlow(params: FlowStartDTO) {
  return axios.post(`/flow/flow/startFlow`, params);
}

// 判断当前用户是否持有这个任务
export function checkProcessRunningAtThisTaskAndUser(taskId: string) {
  return axios.get(`/flow/flow/checkProcessRunningAtThisTaskAndUser/${taskId}`);
}
export interface HandleFlowDTO {
  assignees?: [];
  assigneesInfo?: [];
  toUserInfo?: [];
  backActivityId: string;
  cascade?: true;
  formId: string;
  multiSignTag?: string;
  opinion: string;
  parameters?: any;
  processInstanceId: string;
  defaultRemark: string;
  remark: string;
  taskId: string;
  toUserId: string;
  toUserName: string;
}

// 办结任务
export function handleTask(params: HandleFlowDTO) {
  return axios.post(`/flow/flow/handleTask`, params);
}

export interface HistoricActivityInstanceVO {
  id: string;
  activityId: string;
  activityName: string;
}

// 历史节点查询
export function getHistoryActivitys(formId: string) {
  return axios.get<HistoricActivityInstanceVO[]>(
    `/flow/flow/getHistoryActivitys/${formId}`
  );
}

// 通过表单id获取审批意见列表,是否正序
export function queryApproveRemarkList(formId: string) {
  return axios.get(`/flow/flow/queryApproveRemarkList/${formId}/${true}`);
}

export interface DefaultDealerDTO {
  id: string;
  identity: string;
  name: string;
}

export interface flowNodeList {
  activityId: string;
  defaultDealers: DefaultDealerDTO[];
  approvalSkipAddDTO: {
    activityId: string;
    activityName: string;
    customContent: string;
    processDefinitionKey: string;
    skipType: string;
  };
  eventList: [
    {
      activityId: string;
      dealResultWay: string;
      interceptPattern: string;
      methodType: string;
      opinion: string;
      parameterRelations: {
        additionalProp1: string;
        additionalProp2: string;
        additionalProp3: string;
      };
      path: string;
      title: string;
    }
  ];
  noticeWay: string;
}

export interface flowDeployDTO {
  // bpmnXmlString: string;
  fileName: string;
  processDefinitionKey: string;
  processDefinitionName: string;
  processDefinitionVersion: string;
  bpmnXmlString?: string;
  flowNodeList: flowNodeList[];
  classificationId: string;
}

// 部署流程模板文件
// export function deployV2(params: flowDeployDTO) {
//   return axios.post(`/flow/flow/deploy/v2`, params);
// }

export function deployV3(params: flowDeployDTO) {
  return axios.post(`/flow/flow/deploy/v3`, params);
}

export function deploy(params: { file: any }) {
  return axios.post(`/flow/flow/deploy`, params);
}

export interface ProcessParams extends Pagination {
  processDefinitionKey: string;
  tenantId: string;
  classificationId: string;
}
export interface ProcessVO {
  deploymentId: string; // 流程部署id
  description: string; // 流程描述
  id: string; // 流程定义id
  processDefinitionKey: string; // 流程定义key
  processDefinitionName: string; // 流程定义名称
  processDefinitionVersion: string; // 流程当前版本
}
// 获取当前租户下所有流程定义信息 可通过name模糊查询
export function getProcessDefinitionsByTenantId(params: Pagination) {
  return axios.post<PaginationData<ProcessVO>>(
    `/flow/flow/getProcessDefinitionList`,
    params
  );
}

// 删除
export function deleteDeploy(processDefinitionKey: string) {
  return axios.post(`/flow/flow/deploy/delete/v2/${processDefinitionKey}`);
}

// 详情
export function getDetailByProcessDefinitionKey(processDefinitionKey: string) {
  return axios.get(
    `/flow/flow/getDetailByProcessDefinitionKey/${processDefinitionKey}`
  );
}

export function getBpmnXmlByProcessDefKey(processDefinitionKey: string) {
  return axios.get(
    `/flow/flow/getBpmnXmlByProcessDefKey/${processDefinitionKey}`
  );
}

export function getFlowRunningSituationByFormId(formId: string) {
  return axios.get(`/flow/flow/getFlowRunningSituationByFormId/${formId}`);
}

export interface FlowClassificationVo {
  classificationDescription: string; // 类别描述
  classificationName: string; // 类别名称
  classificationSort: string; // 类别排序
  createOrgId: string; // 创建组织ID
  createOrgName: string; // 创建组织名称
  createTime: string;
  creator: string; // 创建人id
  creatorName: string; // 创建人名称
  deleteFlag: string; // 是否删除,1已删除,0正常
  id: string;
  parentId: string; // 父级id
  parentName: string; // 父级名称
  tenantId: string; // 租户ID
  versionTime: string; // 时间戳
}
export interface CreateOrUpdateFlowClassification {
  id?: string;
  parentId: string; // 父级id
  parentName: string; // 父级名称
  classificationDescription: string; // 类别描述
  classificationName: string; // 类别名称
  classificationSort: number; // 类别排序
}
export interface FlowClassificationTreeVo extends FlowClassificationVo {
  children: FlowClassificationTreeVo[];
}
// 查询流程分类
export function getFlowClassification() {
  return axios.post<FlowClassificationVo[]>(
    `flow/flowClassification/listDataDictionaryClassification`
  );
}

// 新增或编辑流程分类
export function createOrUpdateFlowClassification(
  data: CreateOrUpdateFlowClassification
) {
  return axios.post(
    `flow/flowClassification/insertOrUpdateDataDictionaryClassification`,
    data
  );
}
// 删除流程分类
export function delFlowClassification(ids: string[]) {
  return axios.post(
    `flow/flowClassification/deleteDataDictionaryClassification?ids=${ids}`
  );
}

export interface FlowNodeCallConfigVO {
  eventName: string;
  id: string;
  innerPathFlag: string;
  methodType: string;
  path: string;
}
export interface QueryConfigVO {
  activityId: string;
  activityName: string;
  configList: FlowNodeCallConfigVO[];
}

export interface FlowNodeCallConfigActivityDTO {
  detail: QueryConfigVO[];
  processDefinitionKey: string;
  processDefinitionName: string;
}

// 根据节点Id查询审批流程监听
export function queryFlowNodeCallByProcessDefinitionKey(
  processDefinitionKey: string
) {
  return axios.post<QueryConfigVO[]>(
    `flow/flowNodeCallConfig/queryFlownodecallByProcessDefinitionKey?processDefinitionKey=${processDefinitionKey}`
  );
}

// 根据节点新增或编辑审批流监听设置
export function insertOrEditNodeCallConfigForActivity(
  params: FlowNodeCallConfigActivityDTO
) {
  return axios.post(
    `flow/flowNodeCallConfig/insertOrEditNodeCallConfigForActivity`,
    params
  );
}
// 分页查询预警信息列表
export function pullWarningPageList(params: Pagination) {
  return axios.post(`flow/todo/warningPage`, params);
}
export interface messageList {
  activityName: string;
  applicationCode: string;
  applicationName: string;
  completeFlag: string;
  content: string;
  createOrgId: string;
  createOrgName: null;
  createTime: string;
  creator: string;
  creatorName: string;
  deleteFlag: string;
  formId: string;
  id: string;
  keyWords: string;
  param: string;
  path: string;
  realDealer: null;
  realDealerName: null;
  targetDealer: string;
  task: null;
  taskId: string;
  tenantId: string;
  title: string;
  type: string;
  useTerminal: string;
  versionTime: string;
  remindType: string;
}
// 分页查询消息提醒列表
export function pullMessageList(params: Pagination) {
  return axios.post(`flow/todo/page`, params);
}
